<?php
include_once 'databaseconnection.php';
$_SESSION['successcre']="";
$First_Name=$_POST['First_Name'];
$Last_Name=$_POST['Last_Name'];
$NIC_Number=$_POST['NIC_Number'];
$E_Mail=$_POST['E_Mail'];
$Login_Username=$_POST['Login_Username'];
$Password=$_POST['Password'];
$PasswordVar=$_POST['PasswordVar'];
$Access_Type=$_POST['Access_Type'];
if($First_Name!=""&&$Last_Name!=""&&$NIC_Number!=""&&$E_Mail!=""&&$Login_Username!=""&&$Password!="")
	{
	$pw=$Password;
	$pwlen=strlen($pw);
	$pwre=$pw;
	if($Access_Type=="Select One")
	{
	$_SESSION['errorat']="Please select your access type!";
	}
	if($Access_Type!="Select One")
	{
	 if($PasswordVar=="")
 {
 $_SESSION['errorveri']="Please Verify your Password!";
 }
 if($PasswordVar!="")
 {
if($Password!=$PasswordVar)
{
$_SESSION['errorverify']="Your verification is failed please try again!";
}
if($Password==$PasswordVar)
{
	 $md5pass=md5($Password);
	 $getun=mysql_query("SELECT * FROM user WHERE Login_Username='$Login_Username'");
	 if(mysql_num_rows($getun)!=0)
	 {
	 $_SESSION['errorusna']="Your user name is not valid please try again!";
	 }
	 if(mysql_num_rows($getun)==0)
	 {
	 date_default_timezone_set("Europe/Paris");
    $t_d=date("Y/m/d");
$sql=mysql_query("INSERT INTO user(First_Name,Last_Name,NIC_Number,Access_Type,E_Mail,Login_Username,Password,Last_Updated_Date) VALUES('$First_Name','$Last_Name','$NIC_Number','$Access_Type','$E_Mail','$Login_Username','$md5pass','$t_d')");
if($sql)
  {
  unset($_SESSION['username']);
  unset($_SESSION['Access_Type']);
  unset($_SESSION['First_Name']);
  unset($_SESSION['Last_Name']);
  $_SESSION['successcre']="succ";
$_SESSION['success']="Yes";
 $_SESSION['Access_Type']=$Access_Type;
 $_SESSION['First_Name']=$First_Name;
 $_SESSION['Last_Name']=$Last_Name;
 $_SESSION['username']=$Login_Username;
 $_SESSION['password']=$Password;
 if($Access_Type=="Teacher in Charge"||$Access_Type=="Teacher")
 {
$_SESSION['action']=="create";
}
}
if(!$sql)
  {
   $_SESSION['success']="No";
$_SESSION['error']="Sorry unable to create this account!";
}
  }
  }
}
}
}
   
?>
